require 'test/unit'
require 'semantictext/default_tag_factory'
require 'semantictext/rich_text_parser'
require 'semantictext/bulleted_list_parser'

class BulletedListParserTest < Test::Unit::TestCase

  def assert_element(element_class, text, actual)
  	  assert_equal element_class, actual.class
  	  assert_equal text, actual.text
  end

  def test_creating_simple_bulleted_list
    unit = SemanticText::BulletedListParser.new(SemanticText::RichTextParser.new(SemanticText::DefaultTagFactory.new))
    unit.parse_line('*   foogoo')
    unit.parse_line('* second')
    bulleted_list = unit.bulleted_list
    assert_equal SemanticText::Bullet, unit.bulleted_list.content[0].class
    assert_equal SemanticText::Bullet, unit.bulleted_list.content[1].class
    
    span_line1 = unit.bulleted_list.content[0].content[0]
    span_line2 = unit.bulleted_list.content[1].content[0]
    assert_equal SemanticText::Span, span_line1.class, '1st elt of 1st bullet point should be a span'
    assert_equal SemanticText::Span, span_line2.class, '1st elt of 2nd bullet point should be a span'

    assert_equal 1, unit.bulleted_list.content[0].content.size, 'should only be 1 elt in 1st bullet point'
    assert_equal 1, unit.bulleted_list.content[1].content.size, 'should only be 1 elt in 2nd bullet point'
    
    assert_equal "foogoo", span_line1.text
    assert_equal "second", span_line2.text  
  end

  def test_nested_bulleting
    unit = SemanticText::BulletedListParser.new(SemanticText::RichTextParser.new(SemanticText::DefaultTagFactory.new))
    unit.parse_line('* top-level')
    unit.parse_line('** nested')
    
    assert_equal SemanticText::BulletedList, unit.bulleted_list.class
    assert_equal 2, unit.bulleted_list.content.size

    bullet1 =  unit.bulleted_list.content[0]
    assert_equal SemanticText::Bullet, bullet1.class
    assert_equal SemanticText::Span, bullet1.content[0].class
    assert_equal 'top-level', bullet1.content[0].text
    assert_equal 1, bullet1.depth
    
    nested_bulleted_list = unit.bulleted_list.content[1]
    assert_equal SemanticText::BulletedList, nested_bulleted_list.class
    assert_equal 2, nested_bulleted_list.depth
    assert_equal 1, nested_bulleted_list.content.size
    
    nested_bullet_point = nested_bulleted_list.content[0]
    assert_equal SemanticText::Bullet, nested_bullet_point.class
    assert_equal 2, nested_bullet_point.depth
    
    span = nested_bullet_point.content[0]
    assert_equal SemanticText::Span, span.class
    assert_equal 'nested', span.text
  end
  
end
